Use case: Disable unused memory

Note

When external SRAM is not needed, it is possible to disable HAL SRAM to save power.

Code snippet

HAL1

HAL2

The only option to disable SRAM is to deinitialize the HAL SRAM driver. When SRAM is needed again, the initialization sequence must be performed again.

It is possible to disable HAL SRAM without full deinitialization when SRAM is no longer needed, and to re-enable it when the external memory is required again.

@startuml

== Prerequisite: Initialization and configuration ==

== Process ==

note over "User Application": **Perform any access operation**

"User Application" -> "HAL SRAM Driver" : HAL_SRAM_DeInit()
note right
   **Deinitialize the HAL SRAM driver**
   **to disable the HAL SRAM Memory**
   **to save Power**
end note
"User Application"->"HAL SRAM Driver" : HAL_SRAM_Init()
note right
   **Reinitialize the HAL SRAM driver**
   **to enable the HAL SRAM Memory**
   **to reuse SRAM Driver**
end note

note over "User Application": **Perform any access operation**

@enduml

@startuml

==Prerequisite: Initialization and configuration ==

== Process ==

note over "User Application": **Perform any access operation**

"User Application"->"HAL SRAM Driver" : HAL_SRAM_DisableMemory()
note right
   **Disable the HAL SRAM memory**
   **to save Power**
end note

"User Application"->"HAL SRAM Driver" : HAL_SRAM_EnableMemory()
note right
   **Enable the HAL SRAM memory**
   **to reuse SRAM Driver**
end note

note over "User Application": **Perform any access operation**

@enduml

/* Perform any access operation */

/* Deinitialize the SRAM */
HAL_SRAM_DeInit(&hsram);
/* Reinitialize the SRAM */
HAL_SRAM_Init(&hsram, &Sram_Timing, NULL);

/* Perform any access operation */
/* Perform any access operation */

/* Disable an SRAM sub-bank to save power */
HAL_SRAM_DisableMemory(&hsram);
/* Enable the corresponding SRAM sub-bank */
HAL_SRAM_EnableMemory(&hsram);

/* Perform any access operation */

Key changes

  1. In HAL2, SRAM can be disabled/enabled without full deinitialization.

  2. In HAL1, disabling SRAM requires deinitializing and reinitializing the driver.